//
//  LLStatusTopView.swift
//  WeiBoShiBing
//
//  Created by Bingo on 15/10/31.
//  Copyright © 2015年 Bingo. All rights reserved.
//

import UIKit
//
class LLStatusTopView: UIView {
    
    var status:LLStatus?{
        //属性监视器，当属性的值发生改变的时候系统会调用这个方法，我们就在这个方法里面为子控件赋值
        didSet{
            
            if let iconUrl = status?.user?.profile_image_url{
                
                iconView.LL_setImageWithURL(NSURL(string: iconUrl))
            }
            
            nameLabel.text = status?.user?.name
            
            timeLabel.text = NSDate.sinaStringToDate(status?.created_at ?? "").sinaDateDescription()
            
            sourceLabel.text = status?.source
//            
            verifiedView.image = status?.user?.verifiedTypeImage
//
            memberView.image = status?.user?.mbrankImage
        }
        
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        prepareUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //准备UI
    private func prepareUI(){
        
        addSubview(topSeparatopView)
        addSubview(iconView)
        addSubview(nameLabel)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        addSubview(verifiedView)
        addSubview(memberView)
        
        // 添加约束
        topSeparatopView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: self, size: CGSize(width: UIScreen.mainScreen().bounds.width, height: 10))
        
        iconView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView:topSeparatopView, size: CGSize(width: 35, height: 35), offset: CGPoint(x: 8, y: 8))
        
        nameLabel.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: iconView, size: nil, offset: CGPoint(x: 8, y: 0))
        
        timeLabel.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint(x: 8, y: 0))
        
        sourceLabel.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: timeLabel, size: nil, offset: CGPoint(x: 8, y: 0))
        
        memberView.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: nameLabel, size: CGSize(width: 14, height: 14), offset:CGPoint(x: 8, y: 0))
        
        verifiedView.ff_AlignInner(type: ff_AlignType.BottomRight, referView: iconView, size: CGSize(width: 17, height: 17), offset: CGPoint(x: 8.5, y: 8.5))
        
    }
    //懒加载子控件
    private lazy var topSeparatopView:UIView = {
        let view = UIView()
        
        view.backgroundColor = UIColor.init(white: 0.9, alpha: 1)
        return view
        }()
    
    private lazy var iconView = UIImageView()
    
    private lazy var nameLabel:UILabel = UILabel(fonsize: 14, textColoc: UIColor.darkGrayColor())
    
    private lazy var timeLabel:UILabel = UILabel(fonsize: 9, textColoc: UIColor.orangeColor())
    
    private lazy var sourceLabel:UILabel = UILabel(fonsize: 9, textColoc: UIColor.lightGrayColor())
    
    private lazy var verifiedView = UIImageView()
    
    private lazy var memberView:UIImageView = UIImageView(image:UIImage(named: "common_icon_membership"))
}
